<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:info-standard-line',
              label: '查看详情',
              onClick: handleOpenDetail.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <DetailModal @register="registerModal" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getOperateLog } from '/@/api/system/system';
  import { columns, searchFormSchema } from './log.data';
  import { useModal } from '/@/components/Modal';
  import DetailModal from './DetailModal.vue';

  export default defineComponent({
    name: 'UserOperateLog',
    components: {
      BasicTable,
      DetailModal,
      TableAction,
    },
    setup() {
      const [registerTable, { reload }] = useTable({
        title: '操作日志',
        api: getOperateLog,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        beforeFetch: (params) => {
          params.startTime = params.createTime ? params.createTime[0] : '';
          params.endTime = params.createTime ? params.createTime[1] : '';
          return params;
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        actionColumn: {
          width: 120,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
      });

      const [registerModal, { openModal }] = useModal();

      function handleOpenDetail(record: Recordable) {
        openModal(true, { record });
      }

      function handleSuccess() {
        reload();
      }

      return {
        registerTable,
        registerModal,
        handleOpenDetail,
        handleSuccess,
      };
    },
  });
</script>
